package top.xiaoshuaila.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
//配置类注解
@Configuration
//swagger2注解
@EnableSwagger2
public class SwaggerConfig {
    //返回的一个配置的docket组
    @Bean
    public Docket docket(Environment environment){
        //设置当前环境打开swagger2
        Profiles profiles=Profiles.of("dev");
        boolean f=environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                //使用自定义apiinfo
                .apiInfo(apiInfo())
                .select()
                //扫描所以包
                .apis(RequestHandlerSelectors.any())
                //全部都不扫描
                //.apis(RequestHandlerSelectors.none())
                //指定扫描包
                .apis(RequestHandlerSelectors.basePackage("top.xiaoshuaila.controller"))
                //search select path
                .paths(PathSelectors.ant("/**"))
                .build()
                //whether swagger enable?
                .groupName("lalala")
                //是否启用该组
                .enable(f);
    }
    //返回的一个配置的docket1组
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName(
                "Asf");
    }
    //自定义aoiinfo
    private ApiInfo apiInfo(){
        return new ApiInfo(
                "我是标题!",
                "Api Documentation",
                "1.0",
                "https://www.xiaoshuaila.top",
                new Contact("啦啦啦","https://www.xiaoshuaila.top",
                        "1135508760@qq.com"),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
